package com.CST.controller.cb;

import com.CST.common.api.Response;
import com.CST.common.api.ResultObject;
import com.CST.dto.cb.DateDTO;

import com.CST.entity.cb.JxCost;
import com.CST.service.cb.IJxCostService;
import com.CST.vo.cb.JXInComeVO;
import com.CST.vo.cb.BudgetAssessmentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qtx
 * @since 2023-05-18
 */
@Api(tags={"绩效成本收入数据"})
@RestController
@RequestMapping("/jxCost")
public class JxCostController {
    @Autowired
    private IJxCostService  service;


    @ApiOperation("修改")
    @PostMapping("/modifyPerformance")
    public ResultObject modifyPerformance(@RequestBody JxCost jxCost) {
        Response response = service.modifyPerformance(jxCost);
        return ResultObject.resultReturn(response);
    }

    @ApiOperation("查询绩效收入明细表")
    @PostMapping("/queryInComeVos")
    public ResultObject queryInComeVos(@RequestBody DateDTO dateDTO) {
        List<JXInComeVO> jxInComeVOS = service.queryInComeVos(dateDTO);
        return ResultObject.success(jxInComeVOS);
    }

    @ApiOperation("导出")
    @PostMapping("/exportExcelJXInCome")
    public void exportExcelJXInCome(HttpServletResponse response, @RequestBody DateDTO dateDTO) {
        service.exportExcelJXInCome(response, dateDTO);
    }


    @ApiOperation("导入")
    @PostMapping("/importExcelJxCost")
    public void importExcelJxCost(@RequestParam("file") MultipartFile file, @RequestParam("year") Integer year,
                                  @RequestParam("month")Integer month,
                                  @RequestParam("type")String type,HttpServletResponse response) throws ClassNotFoundException, IOException {
        service.importExcelJxCost(file,year,month,type,response);
    }


    @ApiOperation("导出模板")
    @PostMapping("/exportExcelJxCostDemo")
    public void exportExcelJxCostDemo(HttpServletResponse response,@RequestParam("type")String type) {
        service.exportExcelJxCostDemo(response,type);
    }


    @ApiOperation("效益考核预算报表")
    @PostMapping("/benefitReportForms")
    public ResultObject<List<BudgetAssessmentVO>> benefitReportForms(@RequestBody DateDTO dateDTO) throws ExecutionException, InterruptedException {
       return ResultObject.success(service.benefitReportForms(dateDTO));
    }

    @PostMapping("/downloadTemplate")
    @ApiOperation("效益考核预算导出下载")
    public void downloadTemplate(HttpServletResponse response, @RequestBody DateDTO dto) throws Exception {
        service.exportExcel(response, dto);
    }


}
